//
//  LZFWKVC.m
//  LZFBuDieJie
//
//  Created by 梁梓烽 on 16/6/23.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "LZFWKVC.h"
#import "LZFMineItem.h"
#import <WebKit/WebKit.h>

@interface LZFWKVC ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property(nonatomic,weak)WKWebView *wkWebView;



@end

@implementation LZFWKVC


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setUpWkWebView];
    
}

-(void)setUpWkWebView
{
    WKWebView *wkWebView=[[WKWebView alloc]initWithFrame:self.view.bounds];
    
    self.wkWebView=wkWebView;
    
    [self.view insertSubview:wkWebView atIndex:0];
    
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:_mineItem.url]];
    
    [wkWebView loadRequest:request];
    
    
    [wkWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
    
    
}


-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    
    self.progressView.progress=self.wkWebView.estimatedProgress;
    
    self.progressView.hidden= (self.progressView.progress==1);
    
}


-(void)dealloc{
    
    [self.wkWebView removeObserver:self forKeyPath:@"estimatedProgress"];
}
@end
